home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Dots & Pixels / headers / screendots.h < prev    next >
C/C++ Source or Header  |  1995-09-29  |  4KB  |  113 lines

  1. #pragma once
  2. //
  3. // screendots is a prototypal class for the maintenance of collections of
  4. // dots on a macintosh screen. It simply stores pixel positions, and can be
  5. // used to do some simple things with this collection of positions.
  6. //
  7. // screendots is intended to be used either to display stereo dots or to display
  8. // monocularly visible dots. This could be split into two different classes, but
  9. // then we would also have to write two different versions of noisedots and flowdots.
  10. // In the current implementation one can switch seamlessly from using stereoscopic
  11. // dots to using monocular dots and vice versa, but that can not be done with
  12. // MoveDots. Instead EraseDots/EraseStereoDots must be called, followed by
  13. // SetStereoDots/SetDots. The maximum disparity allowed is given by
  14. // screenarea::max_error. No checks are made to ensure that this is the case.
  15. // NB: although the SetDots/EraseDots/MoveDots combo is relatively immune to wrong
  16. // ways of calling them (e.g. erasing is never done twice since 'current_intensity'
  17. // gets set to zero the first time) the stereo calls are less forgiving.
  18. //
  19. // 940822: added 'Set/Erase/MoveMultiDots'  and make_a_multimove
  20. // to fulfill a request by Frans to move bars, squares, circles and crosses
  21. // over the screen. The array of ints passed to it is supposed to contain
  22. // offsets relative to the 'current position' of pixels to be 'hit' by the
  23. // operation requested. The offsets can encode both row and column offsets.
  24. // For instance, on a normal 13" (640x480 pixels screen) an offset of
  25. // 638 means: one row down, 2 pixels to the left from the 'real position'.
  26. // Users should use the utility function screenarea::compass2offsets to obtain
  27. // such an array.
  28. //
  29. // 941027: Finally discovered why the 'multi' calls crash horribly. It turns
  30. // out that this is because 'waste_area' is way too small when the figure
  31. // specified spans multiple display lines. => Heavily increased 'max_error'
  32. // (from 20 to 20.000) in order to hide this bug. Also made 'compass2offsets'
  33. // enter the Debugger when a too high offset is encountered.
  34. //
  35. class screendots : public screenarea
  36. {
  37.     public:    
  38.         screendots( int numbits, int xpos, int ypos, int aantaldots);
  39.         screendots( int numbits, screen_position where, int aantaldots);
  40.  
  41.         ~screendots();
  42.         //
  43.         // Call 'make_a_move()' to do a single step
  44.         //
  45.         void make_a_move( const unsigned char diff = 1);
  46.         void make_a_multimove(
  47.             const int *offsets, int numoffsets, const unsigned char diff = 1);
  48.         void make_a_stereo_move( const char disparity = 10);
  49.  
  50.         void SetDots( const unsigned char diff = 1);
  51.         void SetMultiDots(
  52.                 const int *offsets, int numoffsets, const unsigned char diff = 1);
  53.         void SetStereoDots( const char disparity = 10);
  54.  
  55.         void EraseDots();
  56.         void EraseMultiDots( const int *offsets, int numoffsets);
  57.         void EraseStereoDots();        
  58.         //
  59.         // MoveDots does Erase & Set in one loop to prevent flicker
  60.         //
  61.         void MoveDots( const unsigned char diff = 1);
  62.         void MoveMultiDots(
  63.                 const int *offsets, int numoffsets, const unsigned char diff = 1);
  64.         void MoveStereoDots( const char disparity = 10);
  65.  
  66.     protected:
  67.         int numdots;
  68.  
  69.         unsigned char **dot_addresses;
  70.         unsigned char **old_dot_addresses;
  71.         //
  72.         // compute_adresses should fill the array 'dot_addresses',
  73.         // and not change 'old_dot_addresses'. 'swap' swaps the
  74.         // contents of these two pointers.
  75.         //
  76.         virtual void compute_addresses() = 0;
  77.         void swap();
  78.  
  79.         void init( int aantaldots);
  80.         
  81.     private:
  82.         union
  83.         {
  84.             unsigned char current_intensity;    // used by EraseDots
  85.             char current_disparity;                // used by EraseStereoDots
  86.         };
  87. };
  88.  
  89. inline screendots::screendots( int numbits, int xpos, int ypos, int aantaldots)
  90.     : screenarea( numbits, xpos, ypos)
  91. {
  92.     init( aantaldots);
  93. }
  94.  
  95. inline screendots::screendots( int numbits, screen_position where, int aantaldots)
  96.     : screenarea( numbits, where)
  97. {
  98.     init( aantaldots);
  99. }
  100.  
  101. inline screendots::~screendots()
  102. {
  103.     delete dot_addresses;
  104.     delete old_dot_addresses;
  105. }
  106.  
  107. inline void screendots::swap()
  108. {
  109.     unsigned char **temp = dot_addresses;
  110.     dot_addresses     = old_dot_addresses;
  111.     old_dot_addresses = temp;
  112. }
  113.